<%@ include file="/init.jsp"%>


<%@page import="java.util.StringTokenizer"%>
<%@page import="com.liferay.portal.service.ListTypeServiceUtil"%>
<%@page import="com.liferay.portal.model.ListType"%>
<%@ include file="/init.jsp"%>

<%
ListType mappedFee = (ListType) request.getAttribute("mappedFee");
System.out.println("doing ID >>>" + mappedFee.getListTypeId());

List<ListType> mappedSubFees = 
	ListTypeServiceUtil.getListTypes
		("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() );
System.out.println("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() +"<<<");

%>
		
		<aui:layout>
			<aui:column>
				<span class="hder" id="feesName_<%=mappedFee.getListTypeId() %>" ><%=mappedFee.getName() %></span>
			</aui:column>
		</aui:layout>
		
		
		<aui:layout>
			<aui:column columnWidth="33">
				<strong>Area (Sq Meters):</strong>
				<input readonly="readonly" id="area_<%=mappedFee.getListTypeId() %>"  name="area_<%=mappedFee.getListTypeId() %>" type="text"></input>
			</aui:column>
			
			<aui:column columnWidth="33">
				<%
				if(mappedSubFees.size() >= 2){
				%>
				
				<br><select  onChange="pickFee(this, <%=mappedFee.getListTypeId() %>); selectedFees_<%=mappedFee.getListTypeId() %>();
					computeSurveyFees();" id="purpose_<%=mappedFee.getListTypeId() %>" name="purpose_<%=mappedFee.getListTypeId() %>"    >
					<option value="">-Select purpose-</option>
				<%
				for(int h=0; h<mappedSubFees.size(); h++){
					ListType mappedSubFee = mappedSubFees.get(h);
					String name = mappedSubFee.getName();
					StringTokenizer strTok = new StringTokenizer(name, "~");
					String firstPart, secondPart, fees;
					firstPart= secondPart= fees ="";
					try{
						 firstPart = strTok.nextToken().replaceAll(mappedFee.getName(), "");
						 secondPart = strTok.nextToken();
						 fees = strTok.nextToken();
					}catch(Exception ex){
						
					}
					
				%>
				<option value="<%= fees %>"><%=firstPart  %></option>
        <%
				}
        %>
                 		
			</select>
			
			<%
			}
			%>
			</aui:column>
			
			<aui:column columnWidth="33">
				<%
				if(mappedSubFees.size() >= 2){
					
				%>
				<br><input class="resultbox" readonly="readonly" id="result_<%=mappedFee.getListTypeId() %>" name="result_<%=mappedFee.getListTypeId() %>" type="text">
				<%
				}
				else if(mappedSubFees.size() == 1) {				
					ListType mappedSubFee = mappedSubFees.get(0);
					StringTokenizer strTok = new StringTokenizer(mappedSubFee.getName(), "~");
					String firstPart, secondPart, fees;
					firstPart= secondPart= fees ="";
					try{
						 firstPart = strTok.nextToken(); //.replaceAll(mappedFee.getName(), "");
						 secondPart = strTok.nextToken();
						 fees = strTok.nextToken();
					}catch(Exception ex){
						
					}
				%>
				<br><input class="resultbox" readonly="readonly" name="result_<%=mappedFee.getListTypeId() %>"  id="result_<%=mappedFee.getListTypeId() %>" type="text" value="<%=fees %>">
				
				<%}
				%>
			</aui:column>
			
		</aui:layout>
		
		<aui:layout>
			<aui:column columnWidth="33">
				<aui:button onClick="computeSurveyFees();" name="compute_result" value="Compute"></aui:button>
			</aui:column>
			<aui:column columnWidth="66">
				<div id="selected_<%=mappedFee.getListTypeId() %>" style="visibility: hidden;"></div>
			</aui:column>
		</aui:layout>
		
			
	
	

<script>
function selectedFees_<%=mappedFee.getListTypeId() %>(){
	try{
		var selectedValue = document.getElementById('purpose_<%=mappedFee.getListTypeId() %>').value;
		document.getElementById('selected_<%=mappedFee.getListTypeId() %>').innerHTML=selectedValue;
		
	}catch(err){
	  alert(err.message);
	}
	
}


function computeSurveyFees(){
	try{
		var result = document.getElementById('result_<%=mappedFee.getListTypeId() %>');
		var area = document.getElementById('area_<%=mappedFee.getListTypeId() %>').value;
		var purpose = document.getElementById('purpose_<%=mappedFee.getListTypeId() %>').value;
		var purpose1 =  purpose.split(" ",1);
	
		result.value = parseFloat(purpose1 * area).toFixed(3);
		hidePrintButton();
		computeTotal();
	}catch(err){
	  txt="There was an error on this page.\n\n";
	  err.message;
	  txt+="Error description: " + err.description + "\n\n";
	  txt+="Click OK to continue.\n\n";
	  txt+=err.message + "\n\n";
	  alert(txt);
	}
	
}
</script>